package com.lsx.logisticscore.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lsx.logisticscore.entity.Employee;
import com.lsx.logisticscore.mapper.EmployeeMapper;
import com.lsx.logisticscore.request.EmployeeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeService {
    @Autowired
    private EmployeeMapper mapper;


    /**
     * 列出员工清单
     * @return
     */
    public List<Employee> listEmployee(){
        return mapper.listEmployee();
    }

    /**
     * 筛选员工
     * @return
     */
    public IPage<Employee> getEmployee(Page<Employee> page, EmployeeVO vo){
        return mapper.selectEmployeeByCondition(page, vo);
    }

    public Employee getEmployeeById(String empId){
        QueryWrapper<Employee> wrapper=new QueryWrapper<>();
        wrapper.eq("emp_id", empId);
        return mapper.selectOne(wrapper);
    }

    public List<Map<String, String>> getEmpCountByType(){
        return mapper.selectEmpCountByType();
    }

    public int updateEmployee(Employee employee){
        UpdateWrapper<Employee> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("emp_id", employee.getEmpId());
        return mapper.update(employee, updateWrapper);
    }

    public int deleteEmployeeById(String empId){
        QueryWrapper<Employee> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("emp_id", empId);
        return mapper.delete(queryWrapper);
    }

    public int insertEmployee(Employee employee){
        employee.setEntryDate(new Date());
        return mapper.insertSelective(employee);
    }
}
